using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

namespace MUSA
{
    public class Camera
    {
        #region Member Variables

        //Camera Matrices
        private static Matrix viewMatrix;
        private static Matrix projectionMatrix;

        //View Attributes
        private Vector3 cameraPosition;
        private Vector3 cameraLookAt;

        //Projection Attributes
        private float fieldOfView = MathHelper.ToRadians(45);
        private float width;
        private float height;
        //private float nearClip = 0.1f;
        //private float farClip = 1000.0f;

        #endregion

        #region Properties

        public Matrix View
        {
            get
            {
                return viewMatrix;
            }
        }

        public Matrix Projection
        {
            get
            {
                return projectionMatrix;
            }
        }

        public float CameraWidth
        {
            get
            {
                return width;
            }
        }

        public float CameraHeight
        {
            get
            {
                return height;
            }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Primary Camera Constructor
        /// </summary>
        /// <param name="cp">Camera Position</param>
        /// <param name="cla">Camera Look At</param>
        public Camera(Vector3 cp , Vector3 cla)
        {
            cameraPosition = cp;
            cameraLookAt = cla;

            UpdateCamera();
        }

        #endregion

        #region Public Methods

        private void UpdateCamera()
        {
            viewMatrix = Matrix.CreateLookAt(cameraPosition , cameraLookAt , Vector3.Up);
            //projectionMatrix = Matrix.CreatePerspectiveFieldOfView(fieldOfView, MUSA.mGraphicsDevice.Viewport.Width / MUSA.mGraphicsDevice.Viewport.Height, nearClip, farClip);

            width = MUSA.mGraphicsDevice.Viewport.Width / 8;
            height = MUSA.mGraphicsDevice.Viewport.Height / 8;

            projectionMatrix = Matrix.CreateOrthographic(width , height , 1 , 100);
        }

        public void Input()
        {
            KeyboardState keyboardState = Keyboard.GetState();
            UpdateCamera();
        }

        #endregion
    }
}
